﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;
using System.Data;
using ReportMobile.inc;

namespace ReportMobile.v2 {
    public partial class RepaymentRate : System.Web.UI.Page {
        public DataSet ds = new DataSet();
        public DataTable dt = new DataTable();
        public Common cm = new Common();
        public string repayYear;    //用户选择的年度
        public string daedTime;     //截止时间
        public double rmbTotal;     //借出合计
        //public string areaName;     //区域名称
        public double totalDQJK, totalYHDQJK, totalDQWH, totalHKL;
        public RepayInfo syb = new RepayInfo();
        public RepayInfo cyq = new RepayInfo();
        public RepayInfo fcy = new RepayInfo();
        protected void Page_Load(object sender, EventArgs e) {

            if (Request.QueryString["y"] == null)
                repayYear = string.Format("{0:yyyy}", DateTime.Now);
            else
                repayYear = Request.QueryString["y"].ToString();

            string urlArea = "syb";
            daedTime = Convert.ToInt32(repayYear) < Convert.ToInt32(string.Format("{0:yyyy}", DateTime.Now)) ?
                        repayYear + "-12-31 00:00:00" : DateTime.Now.ToString();
            dt = cm.ExecuteProcedure("Feed_RepaymentRate @sfYear = " + repayYear + ",@sfArea = " + urlArea);
            syb.JCZE = Convert.ToDouble(dt.Compute("sum(借出总额)", ""));
            syb.DQJK = Convert.ToDouble(dt.Compute("sum(到期借款)", ""));
            syb.DQWH = Convert.ToDouble(dt.Compute("sum(到期未还)", ""));
            syb.YCHDQJK = Convert.ToDouble(dt.Compute("sum(已偿还到期金额)", ""));
            syb.HKL = syb.YCHDQJK / syb.DQJK;

            //川渝区
            urlArea = "cyq";
            cyq.HKLDetails = cm.ExecuteProcedure("Feed_RepaymentRate @sfYear = " + repayYear + ",@sfArea = " + urlArea);
            cyq.JCZE = Convert.ToDouble(cyq.HKLDetails.Compute("sum(借出总额)", ""));
            cyq.DQJK = Convert.ToDouble(cyq.HKLDetails.Compute("sum(到期借款)", ""));
            cyq.DQWH = Convert.ToDouble(cyq.HKLDetails.Compute("sum(到期未还)", ""));
            cyq.YCHDQJK = Convert.ToDouble(cyq.HKLDetails.Compute("sum(已偿还到期金额)", ""));
            cyq.HKL = cyq.YCHDQJK / cyq.DQJK;
            cyq.HKLDetails.DefaultView.Sort = "还款率 desc";   //还款率明细表排序
            cyq.HKLDataSource.Tables.Add(cyq.HKLDetails.DefaultView.ToTable());
            rptRateCYQ.DataSource = cyq.HKLDataSource;
            rptRateCYQ.DataBind();

            //非川渝
            urlArea = "fcy";
            fcy.HKLDetails = cm.ExecuteProcedure("Feed_RepaymentRate @sfYear = " + repayYear + ",@sfArea = " + urlArea);
            fcy.JCZE = Convert.ToDouble(fcy.HKLDetails.Compute("sum(借出总额)", ""));
            fcy.DQJK = Convert.ToDouble(fcy.HKLDetails.Compute("sum(到期借款)", ""));
            fcy.DQWH = Convert.ToDouble(fcy.HKLDetails.Compute("sum(到期未还)", ""));
            fcy.YCHDQJK = Convert.ToDouble(fcy.HKLDetails.Compute("sum(已偿还到期金额)", ""));
            fcy.HKL = fcy.YCHDQJK / fcy.DQJK;
            fcy.HKLDetails.DefaultView.Sort = "还款率 desc";   //还款率明细表排序
            fcy.HKLDataSource.Tables.Add(fcy.HKLDetails.DefaultView.ToTable());
            rptRateFCY.DataSource = fcy.HKLDataSource;
            rptRateFCY.DataBind();


        }
    }
}